package logic

import (
	"context"
	"house/models"

	"house/house"
	"house/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderLogic {
	return &CreateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房源发布权限
func (l *CreateOrderLogic) CreateOrder(in *house.CreateOrderReq) (*house.CreateOrderResp, error) {
	// todo: 创建下单订单
	var err error
	o := models.Order{
		UserId:     int(in.UserId),
		HouseId:    int(in.HouseId),
		Types:      int(in.Types),
		OutTradeNo: in.OutTradeNo,
		Price:      float64(in.Price),
	}
	err = o.Create()
	if err != nil {
		logx.Error("下单失败")
		return nil, err
	}
	return &house.CreateOrderResp{
		Id: int64(o.ID),
	}, nil
}
